/* hardware.h

Copyright (C) Alex S. (mailto: md5sum@alexsp.ru)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details
http://www.gnu.org/licenses/gpl-2.0.html.

You should have received a copy of the GNU General Public License
along with this program in the file gpl-2.0.txt;
if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


#ifndef HARDWARE_H_
#define HARDWARE_H_
#include <avr/io.h>

/* Отладка HP03*/
//#define HP03_DEBUG 1

/*Использовать собаку? собаку желательно не меньше 1 сек*/
#define USE_Watchdog 1
/*Датчик влажности SHT21 или SHT10 установлен ? указать значение 0,10,21*/
#define HUMIDITY 21
/*расположение датчиков ds1820 указываем DDRx !!!!*/
#define DS1820_1_port DDRB
#define DS1820_1_bit (1<<PB0)
#define DS1820_2_port DDRB
#define DS1820_2_bit (1<<PB1)

#define DS1820_1 (uint8_t *) &DS1820_1_port , DS1820_1_bit
#define DS1820_2 (uint8_t *) &DS1820_2_port , DS1820_2_bit

#if (F_CPU < 4000000UL)
#error "Тактовая частота должна быть не меньше 4МГц"
#error "The clock frequency must be greater than or equal to 4MHz"
#endif

#if USE_Watchdog==1
#include <avr/wdt.h>
#define WATCHDOG_TIME WDTO_2S
#endif

#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <util/atomic.h>
#include <stdlib.h>
#include <util/delay.h>
#include <util/crc16.h>
#include <math.h>
#include <string.h>
#include "usart.h"
#include "eep.h"
#include "menu.h"

typedef enum{SUCCESS=0,ERROR,CRC,SHORT,OPEN,WAIT,CLOCK_STOP} hw_ret_status;
#define DISPLAY_PRESSURE 100
#define DISPLAY_MENU 101
#define DISPLAY_CLOCK 102

void lcd_backlight_on(uint8_t);
void lcd_backlight_off();

#if HUMIDITY>0
int16_t dew_point(float rh, float t);
#endif

//#define Timer_OK (1<<0)
#define Press_OK (1<<1)
#define Termo1_OK (1<<2)
#define Termo2_OK (1<<3)
extern uint8_t hw_flags;

extern volatile uint8_t sec_flag;
extern int16_t hop03_correct;
extern uint8_t led_power_max,led_power_min;
extern uint8_t led_time;
extern uint8_t led_time_left;
extern EEMEM int16_t save_hop03_correct;
extern EEMEM uint8_t save_led_power_max,save_led_power_min;
extern EEMEM uint8_t save_led_time;
extern EEMEM uint8_t eep_display_mode;
extern volatile void * save_eep;
extern volatile void * save_ram;
//extern volatile uint8_t print_menu_clock;
extern uint8_t redrawall;
//void print_init_progress(uint8_t percent);

extern uint8_t display_mode;


#endif /* HARDWARE_H_ */
